import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/**
 * <p>
 * </p>
 *
 * @author zhuolin
 * @since 2020/6/3
 */
public class SemapDemo implements Runnable {

    final Semaphore semaphore = new Semaphore(5);

    @Override
    public void run() {
        try {
            semaphore.acquire();
            Thread.sleep(1000L);
            System.out.println(Thread.currentThread().getId()+"done");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
//            semaphore.release();
        }
    }

    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(20);
        final SemapDemo demo = new SemapDemo();
        for(int i = 0 ; i <20;i++){
            es.submit(demo);
        }
    }
}
